package com.example.demo.controller;

import com.example.demo.entity.Student;
import com.example.demo.entity.Table;
import com.example.demo.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.ServerEndpoint;
import java.util.List;

/**
 * @className: com.example.demo.controller-> StudentController
 * @description: 学生的Controller
 * @author: 刘幸
 * @createDate: 2021-04-26 14:47
 * @version: 1.0
 * @todo:
 */
@Controller
public class StudentController {
    @Autowired
    StudentMapper studentMapper;


    @RequestMapping("lookAllStudent")
    public String getAllStudent(){
        return "student/getAllStudent";
    }

    @ResponseBody
    @RequestMapping("/getAllStudent")
    public Table getAllStudent(@RequestParam("page") int page,
                               @RequestParam("limit") int limit){
        List<Student> pageStudent = studentMapper.getPageStudent((page - 1) * limit, limit);
        Table<Student> studentTable = new Table<>();
        studentTable.setData(pageStudent);
        studentTable.setCount(studentMapper.getStudentCount());
        return studentTable;
    }
}
